load("D:/OneDrive - London School of Economics/Desktop/lse assignments/GV390/.RData")
results_table <- modelsummary(models, output = "default", Notes="Note: Effective observations for SC and SDID are smaller due to zero time and unit weights.",
stars = c('*' = .1, '**' = .05, '***' = .01),
title = "Poll: Rejection of Taiwan independence.",
coef_rename = c("treated" = "ATT"),  gof_map = gofmap)
need <- c("foreign", "readstata13", "tidyverse", "estimatr", "csvy","synthdid", "modelsummary",
"devtools", "dplyr", "tidyr", "lubridate","fixest", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
results_table
results_table <- modelsummary(models, output = "default", Notes="Note: Effective observations for SC and SDID are smaller due to zero time and unit weights.",
stars = c('*' = .1, '**' = .05, '***' = .01),
title = "Poll: Rejection of Taiwan independence.",
coef_rename = c("treated" = "ATT"),  gof_map = gofmap)
results_table
results_table <- modelsummary(models, output = "default", Notes="Note: Effective observations for SC and SDID are smaller due to zero time and unit weights.",
stars = c('*' = .1, '**' = .05, '***' = .01),
title = "Poll: Rejection of Taiwan independence.",
coef_rename = c("treated" = "ATT"),  gof_map = gofmap)
results_table
results_table <- modelsummary(models, output = "default", notes="Note: Effective observations for SC and SDID are smaller due to zero time and unit weights.",
stars = c('*' = .1, '**' = .05, '***' = .01),
title = "Poll: Rejection of Taiwan independence.",
coef_rename = c("treated" = "ATT"),  gof_map = gofmap)
results_table
load("D:/OneDrive - London School of Economics/Desktop/lse assignments/GV390/cleaned data/conpol.Rdata")
original <- a
load("D:/OneDrive - London School of Economics/Desktop/replication/cleaned data/conpol.Rdata")
replicated <- a
View(replicated)
View(original)
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "cleaned data", sep = "/")) #select raw data directory
load("D:/OneDrive - London School of Economics/Desktop/replication/cleaned data/satecon.Rdata")
View(a)
replicated <- a
load("D:/OneDrive - London School of Economics/Desktop/lse assignments/GV390/cleaned data/satecon.Rdata")
original <- a
View(replicated)
View(original)
rm(list = ls()) # clear workspace
name_list <- c("conpol","conecon","conlive","satpol", "satecon","satlive")
anti_Beijing <- c()
sensitivity <- c("low","low","low","medium","low","low")
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "raw data", sep = "/")) #select raw data directory
list<- lapply(name_list, function(name) {
read.csv(paste0(name, ".csv"))
}) #read the datasets into a large list
names(list) <- name_list
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "cleaned data", sep = "/")) #select raw data directory
for (name in name_list) {
list[[name]]<- rename(list[[name]], Date= "調查開始日期Survey.Start.Date")
list[[name]]$Date <- as.Date(list[[name]]$Date)
if ("淨值Net.Value" %in% names(list[[name]]) | "淨值Netvalue" %in% names(list[[name]]) | "淨值Net.value" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(proBeijing="淨值Net.Value", proBeijing="淨值Netvalue", proBeijing="淨值Net.value")))
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else { if("評分Rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (as.numeric(sub("%","",list[[name]]$評分Rating))-5)*20
} else { if("支持度Support.rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (list[[name]]$支持度Support.rating-50)*2
} else{print(colnames(list[[name]])[6])
if("唔知.難講DK.HS" %in% names(list[[name]])){
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else{print(paste0("ALERT: ",name," Variable:",colnames(list[[name]])[6]))
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))}
}
}
}
if(name %in% anti_Beijing) {
print(paste0(name," is an anti-Beijing poll"))
list[[name]]$proBeijing=-list[[name]]$proBeijing}
if ("認知率Recognition.Rate" %in% names(list[[name]]) |"認知率Recognition.rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(recognition="認知率Recognition.Rate",recognition="認知率Recognition.rate")))
list[[name]]$recognition <- as.numeric(sub("%","",list[[name]]$recognition))
}
if ("回應率Response.rate" %in% names(list[[name]]) |"回應率Response.Rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(response="回應率Response.rate",response="回應率Response.Rate")))
list[[name]]$response <- as.numeric(sub("%","",list[[name]]$response))
}
list[[name]]$sensitivity <- sensitivity[which(name_list==name)]
a <- list[[name]] %>% select(any_of(c("Date","response","recognition","proBeijing","sensitivity")))
print(colnames(a))
save(a,file=paste(name, "Rdata", sep="."))
}
need <- c("dplyr", "tidyr") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
rm(list = ls()) # clear workspace
name_list <- c("conpol","conecon","conlive","satpol", "satecon","satlive")
anti_Beijing <- c()
sensitivity <- c("low","low","low","medium","low","low")
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "raw data", sep = "/")) #select raw data directory
list<- lapply(name_list, function(name) {
read.csv(paste0(name, ".csv"))
}) #read the datasets into a large list
names(list) <- name_list
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "cleaned data", sep = "/")) #select raw data directory
for (name in name_list) {
list[[name]]<- rename(list[[name]], Date= "調查開始日期Survey.Start.Date")
list[[name]]$Date <- as.Date(list[[name]]$Date)
if ("淨值Net.Value" %in% names(list[[name]]) | "淨值Netvalue" %in% names(list[[name]]) | "淨值Net.value" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(proBeijing="淨值Net.Value", proBeijing="淨值Netvalue", proBeijing="淨值Net.value")))
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else { if("評分Rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (as.numeric(sub("%","",list[[name]]$評分Rating))-5)*20
} else { if("支持度Support.rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (list[[name]]$支持度Support.rating-50)*2
} else{print(colnames(list[[name]])[6])
if("唔知.難講DK.HS" %in% names(list[[name]])){
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else{print(paste0("ALERT: ",name," Variable:",colnames(list[[name]])[6]))
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))}
}
}
}
if(name %in% anti_Beijing) {
print(paste0(name," is an anti-Beijing poll"))
list[[name]]$proBeijing=-list[[name]]$proBeijing}
if ("認知率Recognition.Rate" %in% names(list[[name]]) |"認知率Recognition.rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(recognition="認知率Recognition.Rate",recognition="認知率Recognition.rate")))
list[[name]]$recognition <- as.numeric(sub("%","",list[[name]]$recognition))
}
if ("回應率Response.rate" %in% names(list[[name]]) |"回應率Response.Rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(response="回應率Response.rate",response="回應率Response.Rate")))
list[[name]]$response <- as.numeric(sub("%","",list[[name]]$response))
}
list[[name]]$sensitivity <- sensitivity[which(name_list==name)]
a <- list[[name]] %>% select(any_of(c("Date","response","recognition","proBeijing","sensitivity")))
print(colnames(a))
save(a,file=paste(name, "Rdata", sep="."))
}
View(list)
rm(list = ls()) # clear workspace
name_list <- c("conpol","conecon","conlive","satpol", "satecon","satlive")
anti_Beijing <- c()
sensitivity <- c("low","low","low","medium","low","low")
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "raw data", sep = "/")) #select raw data directory
list<- lapply(name_list, function(name) {
read.csv(paste0(name, ".csv"))
}) #read the datasets into a large list
names(list) <- name_list
setwd(paste (dirname(rstudioapi::getSourceEditorContext()$path), "cleaned data", sep = "/")) #select raw data directory
for (name in name_list) {
list[[name]]<- rename(list[[name]], Date= "調查開始日期Survey.Start.Date")
list[[name]]$Date <- as.Date(list[[name]]$Date)
if ("淨值Net.Value" %in% names(list[[name]]) | "淨值Netvalue" %in% names(list[[name]]) | "淨值Net.value" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(proBeijing="淨值Net.Value", proBeijing="淨值Netvalue", proBeijing="淨值Net.value")))
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else { if("評分Rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (as.numeric(sub("%","",list[[name]]$評分Rating))-5)*20
} else { if("支持度Support.rating" %in% names(list[[name]])) {
list[[name]]$proBeijing <- (list[[name]]$支持度Support.rating-50)*2
} else{print(colnames(list[[name]])[6])
if("唔知.難講DK.HS" %in% names(list[[name]])){
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))
} else{print(paste0("ALERT: ",name," Variable:",colnames(list[[name]])[6]))
colnames(list[[name]])[6]<- "proBeijing"
list[[name]]$proBeijing <- as.numeric(sub("%","",list[[name]]$proBeijing))}
}
}
}
if(name %in% anti_Beijing) {
print(paste0(name," is an anti-Beijing poll"))
list[[name]]$proBeijing=-list[[name]]$proBeijing}
if ("認知率Recognition.Rate" %in% names(list[[name]]) |"認知率Recognition.rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(recognition="認知率Recognition.Rate",recognition="認知率Recognition.rate")))
list[[name]]$recognition <- as.numeric(sub("%","",list[[name]]$recognition))
}
if ("回應率Response.rate" %in% names(list[[name]]) |"回應率Response.Rate" %in% names(list[[name]])|"回應比率Response.rate" %in% names(list[[name]])) {
list[[name]]<- rename(list[[name]], any_of(c(response="回應率Response.rate",response="回應率Response.Rate",response="回應比率Response.rate")))
list[[name]]$response <- as.numeric(sub("%","",list[[name]]$response))
}
list[[name]]$sensitivity <- sensitivity[which(name_list==name)]
a <- list[[name]] %>% select(any_of(c("Date","response","recognition","proBeijing","sensitivity")))
print(colnames(a))
save(a,file=paste(name, "Rdata", sep="."))
}
load("D:/OneDrive - London School of Economics/Desktop/replication/cleaned data/conpol.Rdata")
replicated <- a
load("D:/OneDrive - London School of Economics/Desktop/lse assignments/GV390/cleaned data/conpol.Rdata")
original <- a
rm(a)
View(original)
View(replicated)
